package com.zz.bsea.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zz.bsea.model.User;
import com.zz.bsea.service.UserService;
import com.zz.bsea.tool.WeiChatUtil;

@Controller
public class URLController {
	@Autowired
	UserService userService;
	
	@RequestMapping("page1")
	public String toList(HttpServletRequest req){
		String code=req.getParameter("code");
		String openId=WeiChatUtil.getOpenId(code);
		req.getSession().setAttribute("openId", openId);
		System.out.println("code=="+code+" ---openId=="+openId);
		User u=userService.selectByopenid(openId);
		String rs="login2.html";
		if(u!=null){
			rs="pages.html";
			req.getSession().setAttribute("user", u);
		}
		return rs;
	}
}
